
// This is to retrieve all the data at once when the page is loaded. If there's not
// a lot of data, then this way is more efficient than sending a request each time
// a character is typed in.
var init_tokentextbox = function(input_name){
    $(document).ready(function() {
        $.getJSON('/tag_list/', function(result){
            if (result['success']) {
                $('input[name="' + input_name + '"]').tokentextbox({
                    separators: " ",
                    autocomplete_options: {
                        data: result['tags']
                    }
                });
            }
        });
    });
}





/*
1)  If the data is already available, you can simply add the following
    to this javascript file:

        var some_options = {
            data: cities // Assuming 'cities' is an Array, for example: cities=['London', 'Paris', 'Tokyo']
        }

    Then, modify the form in forms.py:
    
        tags = TagField(widget=TokenTextBoxWidget(separators=',', ac_options='some_options'))
    
2)  If you want to load some remote data each time a character is typed in,
    then add the following to this javascript file:
    
        var some_other_options= {
            url: '/blah/'
        }

    Then, modify the form in forms.py:
    
        tags = TagField(widget=TokenTextBoxWidget(separators=',', ac_options='some_other_options'))

    
*/